package com.nbsaas.boot.shopArticle.rest.convert;

import com.nbsaas.boot.shopArticle.data.entity.ShopArticle;
import com.nbsaas.boot.shopArticle.api.domain.request.ShopArticleRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.shop.data.entity.Shop;
            import com.nbsaas.boot.shopArticle.data.entity.ShopArticleCatalog;
            import com.nbsaas.boot.shopArticle.data.entity.ShopArticleDocument;

/**
* 请求对象转换成实体对象
*/

public class ShopArticleEntityConvert  implements Converter<ShopArticle, ShopArticleRequest> {

    @Override
    public ShopArticle convert(ShopArticleRequest source) {
        ShopArticle result = new ShopArticle();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getShop()!=null){
                    Shop shop =new Shop();
                    shop.setId(source.getShop());
                    result.setShop(shop);
                    }
                    if(source.getCatalog()!=null){
                    ShopArticleCatalog catalog =new ShopArticleCatalog();
                    catalog.setId(source.getCatalog());
                    result.setCatalog(catalog);
                    }
                    if(source.getDocument()!=null){
                    ShopArticleDocument document =new ShopArticleDocument();
                    document.setId(source.getDocument());
                    result.setDocument(document);
                    }
        return result;
    }
}

